
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using System.Xml;
using Mehat.San.DiscManager;
using Mehat.San.MediaChanger.MediaChangerDriver;

namespace Mehat.San.MediaChanger
{
	public class MediaChanger : IMediaChanger
	{
		private Mutex					mLock = new Mutex();
		private List<IStorageElement>	mStorageElements = new List<IStorageElement>();
		private IMediaChangerDriver		mDriver; 
		private bool                    mIsBusy;
		
		public MediaChanger(IMediaChangerDriver Driver)
		{
            mDriver = Driver;
            mDriver.MediaChanger = this;
		}
		
		public void Reset()
		{
		    mLock.WaitOne();
		    mIsBusy = true;
		    try
		    {
			    mStorageElements.Clear();
			    mDriver.Reset();
                mStorageElements = mDriver.ReadInventory();
			}
			catch
			{
			    throw;
			}
			finally
			{
			    mIsBusy = false;
			    mLock.ReleaseMutex();
			}
		}
	
		
		public List<IStorageElement> StorageElements
		{
			get { return this.mStorageElements; }
		}
		
		public bool IsBusy
		{
		    get { return mIsBusy; }
		}
		
	}  // END CLASS
}  // END NAMESPACE
